use strict;
use utf8;

my $content;
{
  binmode(STDIN, ":encoding(utf-8)");
  local $/;
  $content = <STDIN>;
}

binmode(STDOUT, ":encoding(utf-8)");

my %fields = ( "stad" => ["название", "местоположение", "команда" ],
               "city" => ["русское название", "страна", "статус"],
               "team" => ["прозвища", "стадион"],
             );
my %r;

if ($#ARGV < 0) { die "object types: " . join(", ", keys %fields); }
my $k = $ARGV[0];

my $id = $1 if ($content =~ /<id>(\d+)<\/id>/);
my $title = $1 if ($content =~ /<title>([^<]+)<\/title>/);

foreach my $f (@{$fields{$k}}) {
  if ($content =~ /^\s*\|\s*$f\s*=\s*(.+)\s*$/m) {
    $r{$f} = $1;
    if ($r{$f} =~ /\s*\[\[([^\]^\|]+)/) { $r{$f . "l"} = $1; }
  };
}

print "$id\t$title";
foreach my $f (@{$fields{$k}}) { print "\t" . $r{$f . "l"}; }
foreach my $f (@{$fields{$k}}) { print "\t$r{$f}"; }
print "\n";
